<?php
/**
 * Remove a document from a ressource 
 * @package Ressource
 */
use Fox\Generator;

$xview = Xview::instance();
$id = Xview::instance()->val('mid');
$accounceid = Xview::instance()->val('aid');
if(empty($accounceid))
{
	Xview::instance()->systemError();exit;
}
try {
	$mission = new Hive\Mission($id);
	$announce = new Hive\Mission\Announce($accounceid.':'.$id);
	$tabLabel = Msg(Hive::BUNDLE,Hive::ANNOUNCE_REFERENCE,$announce->reference);
}
catch (Fox\Object\Exception\NotExist $e)
{
	Xview::instance()->systemError();exit;
}
if( Xview::instance()->val("confirmation"))
{
	try {
		$announce->delete();
		Fox\Message::Information(Msg(Fox::MSGCL,Fox\Msg::MSG_DELETE,$tabLabel));
		
	}
	catch (Fox\Object\Exception\Save $e)
	{
		Fox\Message::Error($e->getMessage());
	}
	echo $xview->messages();
	exit;
}
$reloadGen = Generator::ajaxReload('contentCol',Generator::url('missions','announces',null,array('mid' => $id)));
$yesAction = Generator::ajax(Generator::url('missions','announces','delete',array('mid' => $id,'aid' => $accounceid )),
							'&confirmation=true',
							$reloadGen,'hdeleteForm',null,2
);
$popup = new Fox\Popup\ToConfirm('deleteForm',
					Msg(Fox\Msg::BUNDLE,Fox\Msg::MSG_DELETE_HDR),
					Msg(Fox\Msg::BUNDLE,Fox\Msg::MSG_DELETE_MSG_CONF,$tabLabel),
					$yesAction,null,400);
echo $popup->Display();